﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;

namespace CommonUtils
{
    public class WebApp
    {
        public static bool IsDevelopment { get; private set; }

        private static WebApplication instance;

        public static WebApplication Instance
        {
            get { return instance; }
            set
            {
                instance = value;
                IsDevelopment = value.Environment.IsDevelopment();
            }
        }

        public static IServiceProvider Services { get { return Instance.Services; } }

        public static IConfiguration Configuration { get { return Instance.Configuration; } }

        public static string GetConfiguration(string key) { return Configuration[key]; }

        public static IWebHostEnvironment Environment { get { return Instance.Environment; } }

        public static IHostApplicationLifetime Lifetime { get { return Instance.Lifetime; } }

        public static ILogger Logger { get { return Instance.Logger; } }

        public static ICollection<string> Urls { get { return Instance.Urls; } }
    }
}
